package com.xiaoran.springboot3.controller;


import com.xiaoran.springboot3.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpSession;

@Controller
public class IndexController {

    @GetMapping("/")
    public String loginpage(){
        return "login";
    }

    @PostMapping("/login")
    public String main(User user, HttpSession session, Model model){
        if((!("".equals(user.getUsername()))) && "123".equals(user.getPassword())){
            session.setAttribute("LogUser",user);
            return "redirect:/main.html";
        }
        model.addAttribute("msg","很遗憾老铁重新输入把");
        return "login";
    }

    @GetMapping("/main.html")
    public String mainPage(HttpSession session,Model model){
        /*Object logUser=session.getAttribute("LogUser");
        if(logUser!=null) {
            return "main";
        }else {
            model.addAttribute("msg","当前未登录，请先登录");
            return "login";
        }*/
        return "main";
    }
}
